package com.gec.hawaste.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gec.hawaste.entity.*;
import com.gec.hawaste.mapper.SysUserRoleMapper;
import com.gec.hawaste.service.ISysUserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author gec
 * @since 2022-11-23
 */
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements ISysUserRoleService {
    @Autowired
    SysUserRoleMapper sysUserRoleMapper;

    @Override
    public int deleteBatch(Long rid, Long[] ids) {
        QueryWrapper<SysUserRole> wrapper = new QueryWrapper();
        wrapper.eq("role_id", rid).in("user_id", ids);
        return sysUserRoleMapper.delete(wrapper);
    }

    @Override
    public int insertBatch(Long rid, Long[] ids) {
        for (Long userId : ids) {
            SysUserRole r = new SysUserRole();
            r.setRoleId(rid);
            r.setUserId(userId);
            sysUserRoleMapper.insert(r);
        }
        return 1;
    }



}
